package com.phospherus.user.repository

import com.phospherus.common.repository.BaseRepository
import com.phospherus.user.entity.RoleUser
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

/**
 * @author songjinlong
 * @version 1.0
 * @since 2017/12/03
 */
interface RoleUserRepository : BaseRepository<RoleUser, Long> {
    @Modifying
    @Query(value = "delete from role_user where role_id= :roleId", nativeQuery = true)
    fun deleteByRoleId(@Param("roleId") roleId: Long)

    @Modifying
    @Query(value = "delete from role_user where user_id= :userId", nativeQuery = true)
    fun deleteByUserId(@Param("userId") userId: Long)

    fun findByRoleIdAndUserId(roleId: Long, userId: Long): RoleUser?
}